<?php
class UploadHelper
{
	public static function uploadImage($formName,$websitePath)
	{
		//create upload dir if not exists
		$uploadDir = constant('SITE_WEB_DISK_DIR').$websitePath;
		if(!file_exists($uploadDir))
		{
			mkdir($uploadDir,0755,true);
		}
		//uploading image small image
		if(isset($_FILES[$formName]) && strlen($_FILES[$formName]['tmp_name']) > 0 && strlen($_FILES[$formName]['name']) > 0)
		{
				$ext = Util::getFileExt($_FILES[$formName]['name']);
				$ext = strtolower($ext);
				if($ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "gif" || $ext == "bmp")
				{
					$fileName = time().'.'.$formName.'.'.$ext;
					$targetFilePath  = 	$uploadDir.$fileName;
					move_uploaded_file($_FILES[$formName]['tmp_name'],$targetFilePath);
					return $websitePath.$fileName;	
				}else{
					throw new Exception("Upload file type ".$ext." not allowed");
				}
		}else{
			throw new Exception("Can't find ".$formName." in request parameters");
		}
	}
}
?>